/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-05-25 16:45:02
 * @LastEditTime: 2024-09-07 20:43:17
 * @FilePath: /nest_study/server/src/modules/system/user/user.controller.ts
 */
import { Controller, Get, Post, Body, Request, Query, Put, Delete } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto, DeleteUserDto, ListUserDto, ResetPwdDto, UpdateUserDto } from './dto/index.dto';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';

@ApiTags('用户管理')
// @ApiBearerAuth()
@Controller('system/user')
export class UserController {
  constructor(private readonly userService: UserService) { }

  @ApiOperation({
    summary: '用户-创建'
  })
  @ApiBody({
    type: CreateUserDto,
    required: true
  })
  @Post('/create')
  create(@Body() createUserDto: CreateUserDto, @Request() req) {
    return this.userService.create(createUserDto);
  };

  @ApiOperation({
    summary: "用户-更新"
  })
  @ApiBody({
    type: UpdateUserDto,
    required: true
  })
  @Put('/update')
  update(@Body() updateUserDto: UpdateUserDto, @Request() req) {
    return this.userService.update(updateUserDto);
  }

  @ApiOperation({
    summary: '用户-删除'
  })
  @ApiBody({
    type: DeleteUserDto,
    required: true
  })
  @Delete("/delete")
  remove(@Body() userInfo: DeleteUserDto) {
    return this.userService.remove(userInfo);
  }

  @ApiOperation({
    summary: '用户 - 列表'
  })
  @Get('/list')
  list(@Query() query: ListUserDto, @Request() req) {
    const user = req.user;
    return this.userService.findList(query);
  }


  @ApiOperation({
    summary: '用户-更新/重置密码'
  })
  @ApiBody({
    type: ResetPwdDto,
    required: true
  })
  @Put('/reset')
  reset(@Body() body: ResetPwdDto) {
    return this.userService.resetPassword(body);
  }

}
